<?php

class Post_Model extends CI_Model {

    private $table = 'posts';

    public function __construct() {
        parent::__construct();
        $this->load->database();
    }

    public function create($data) {
        return $this->db->insert($this->table, $data);
    }

    
    public function get_all($where) {
        if (empty($where) == FALSE) {
            $this->db->where($where);
        }

        $this->db->order_by('id', 'DESC');
        $query = $this->db->get($this->table);
        return is_object($query) ? $query->result_array() : FALSE;
    }
    
    public function get($where) {
        if (empty($where) == FALSE) {
            $this->db->where($where);
        }

        $this->db->where('status', 1);
        $this->db->order_by('id', 'DESC');
        $query = $this->db->get($this->table);
        return is_object($query) ? $query->result_array() : FALSE;
    }

    public function get_one($id) {
        $this->db->where('id', $id);
        $query = $this->db->get($this->table);
        return is_object($query) ? $query->row_array() : FALSE;
    }

    public function update($id, $data) {
        $this->db->where('id', $id);
        return $this->db->update($this->table, $data);
    }

}
